<?php 
if(KT!='KhiThe') exit;
class carts_controller extends khithe_mysql {
	
	public function __construct()
	{	
		global $lang;
		
		$lang['url_base'] = url_base;	
		$this->path_cur = dirname(__FILE__);	
		parent::__construct();
		parent::addObject('khithe_template');
		parent::addObject('khithe_request');
		parent::addObject('khithe_string');

		$this->lang = $lang;
	}
	public function index()
	{
        /*==================== View Cart =======================*/
            if(empty($_SESSION['cart'])){
                $this->lang['dis_cart'] = 'style="display:none"';
            }else{
                $this->lang['dis_cart'] = 'style="display:block"';
            }
            $strHtmlContentCart = $this->khithe_display_template($this->path_cur.'/carts');
            $arrBlockHtmlCart = $this->khithe_getBlockHtml($strHtmlContentCart);
            $arrID = explode(',',isset($_SESSION['cart'])?$_SESSION['cart']:NULL);
            $contents = array();
            foreach ($arrID as $item) {
                $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
            }
            $sys = new systems_model();
            $arrRow = $sys->selectProduct($arrID);
            $i=1; $Total_money=0; $tt=0;
            $resultHtmlCart=null;
            if(!empty($arrRow)){
                foreach ($arrRow as $row){
                    $Price = $row['PriceSpecial']!=''?$row['PriceSpecial']/$this->lang["rate"]:$row['Price']/$this->lang["rate"];
                    $Qty = $contents[$row['ID']];
                    $TotalPQ = ($Price * $Qty);
                    $Total_money = $Total_money +$TotalPQ;
                    $tt = $i++;
                    $arrCart = array(

                        'cart_title'=>$row['Title'],
                        'cart_price_hid'=>$Price,
                        'cart_price'=>number_format($Price,0,'.',','),
                        'cart_count'=>$Qty,
                        'cart_ID'=>$row['ID'],
                        'Picture'=>$row['Picture']

                    );


                    $HtmlCart = $this->khithe_assign($arrBlockHtmlCart['Cart'],$arrCart);
                    $resultHtmlCart .= $this->khithe_assign($HtmlCart,$this->lang);

                }

            }


            $this->lang['total_item']=$tt;
            $this->lang['cart_total_money_hid']=$Total_money;
            $this->lang['cart_total_money']=number_format($Total_money,0,'.',',');

            $strHtmlContentCart = $this->khithe_assign($strHtmlContentCart,$this->lang);
            return $this->khithe_assignBlock($strHtmlContentCart, array('htmlCart'=>$resultHtmlCart));


        /*==================== End View Cart =======================*/


	}
	
	
}
?>